/*
 * ConsultaRotas.java
 *
 * Created on 21 de Outubro de 2008, 21:57
 */

package br.faimg.pomar.visual;

import br.faimg.pomar.controle.componentevisual.ComboRotas;
import br.faimg.pomar.controle.componentevisual.ItemTipo;
import br.faimg.pomar.controle.componentevisual.RotaEstacaoGraphModel;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import org.jgraph.JGraph;

/**
 *
 * @author  flavio
 */
public class CadastroRotas extends javax.swing.JInternalFrame {

    /** Creates new form ConsultaRotas */
    public CadastroRotas() {
        initComponents();
        
        updateCombo();
    
    }
    
    /**
     * Atualiza a rota exibida nesta view
     * @param ordemProducao
     */
    public void updateRota(Integer ordemProducao){
        
        JInternalFrame frame = new JInternalFrame("Rota de produção " + ordemProducao);
        
        JGraph graph2 = new JGraph();
        graph2.setModel(new RotaEstacaoGraphModel().getModel(ordemProducao));
        frame.add(new JScrollPane(graph2));
        frame.pack();
        frame.setClosable(true);
        frame.setResizable(true);
        frame.setVisible(true);
        this.getDesktopPane().add(frame,0);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        topjPanel = new javax.swing.JPanel();
        ordemdeProducaojComboBox = new javax.swing.JComboBox();
        cancelarjButton = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        inserirEstacaojButton = new javax.swing.JButton();
        excluirEstacaojButton = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();

        setTitle("Cadastro de rota de produção");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        topjPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        ordemdeProducaojComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        topjPanel.add(ordemdeProducaojComboBox, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, 250, -1));

        cancelarjButton.setText("Fechar");
        cancelarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarjButtonActionPerformed(evt);
            }
        });
        topjPanel.add(cancelarjButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 10, 80, -1));

        jButton1.setText("Ok");
        topjPanel.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 10, 80, -1));

        inserirEstacaojButton.setText("Inserir Estação");
        inserirEstacaojButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inserirEstacaojButtonActionPerformed(evt);
            }
        });
        topjPanel.add(inserirEstacaojButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 70, 150, -1));

        excluirEstacaojButton.setText("Excluir Última Estação");
        topjPanel.add(excluirEstacaojButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 70, 150, -1));

        jButton2.setText("Limpar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        topjPanel.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 70, 150, -1));
        topjPanel.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, 470, -1));

        getContentPane().add(topjPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 510, 110));

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void cancelarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarjButtonActionPerformed

    this.setVisible(false);
}//GEN-LAST:event_cancelarjButtonActionPerformed

private void inserirEstacaojButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inserirEstacaojButtonActionPerformed

    updateRota(Integer.parseInt(((ItemTipo)ordemdeProducaojComboBox.getSelectedItem()).getCodigo()));
}//GEN-LAST:event_inserirEstacaojButtonActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelarjButton;
    private javax.swing.JButton excluirEstacaojButton;
    private javax.swing.JButton inserirEstacaojButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JComboBox ordemdeProducaojComboBox;
    private javax.swing.JPanel topjPanel;
    // End of variables declaration//GEN-END:variables

    private void updateCombo() {
        ordemdeProducaojComboBox.setModel(new JComboBox(new ComboRotas().getList()).getModel());
    }

}
